import 'package:flutter/material.dart';
import 'package:p_location/map/res/dept_tree_info.dart';
import 'package:p_location/utils/string_util.dart';

class DeptItemView extends StatelessWidget {
  final DeptTreeInfo obj;

  final Function onItemClick;
  final Function onArrowClick;

  DeptItemView(this.obj, this.onItemClick, this.onArrowClick);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
//        if (mode == ClickType.selectMode) {
//          Navigator.of(context).pop(obj);
//          this.obj.isExpand = !this.obj.isExpand;
        print('sfsgwererw${obj.id}');
        this.onItemClick();
//        } else {
//          NavigatorUtil.push(context, DeptInfoDetailPage(obj.id.toString()));
//        }
      },
      child: Container(
        color: Colors.white,
        child: Container(
          height: 50,
          alignment: Alignment.center,
          padding: EdgeInsets.fromLTRB(10, 15, 10, 15),
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              Text(
                StringUtil.getEliminateString(obj.label, 17),
                style: TextStyle(
                  color: Colors.black,
                  fontSize: 14,
                ),
              ),
              Offstage(
                offstage: obj.children == null || obj.children.length == 0,
                child: GestureDetector(
                    onTap: () {
                      onArrowClick();
                    },
                    child: Icon(
                      (obj.isExpand
                          ? Icons.keyboard_arrow_up
                          : Icons.keyboard_arrow_down),
                      color: Colors.black,
                    )),
              )
            ],
          ),
        ),
      ),
    );
  }
}
